﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Api.Model;

namespace Api.DAL
{
    public class ProjectDAL : BaseDAL<Project>
    {
        public void DeleteProjects(IQueryable<Project> list)
        {
            dbSet.RemoveRange(list);
            var projectIds = list.Select(s => s.Id);
            var categories = db.Categories.Where(s => projectIds.Contains(s.ProjectId));
            var methods = db.Methods.Where(s => projectIds.Contains(s.ProjectId));
            var methodParameters = db.Parameters.Where(s => projectIds.Contains(s.ProjectId));
            var errorcodes = db.ErrorCodes.Where(s => projectIds.Contains(s.ProjectId));

            db.Categories.RemoveRange(categories);
            db.Methods.RemoveRange(methods);
            db.Parameters.RemoveRange(methodParameters);
            db.ErrorCodes.RemoveRange(errorcodes);

            db.SaveChanges();

            //利用反射找到api.model中所有的继承自IEntity的类，然后获取他们的tablename属性即可实现删除所有的表
        }
    }
}
